import useUserStore from "@/common/store/userStore";

/**
 * 根据用户角色，判断是否显示标签
 * 使用方式： <div  v-has-role="['10','11','12']" > AAA </div>
 */
export default {
    mounted(el, binding, vnode) {
        const {value} = binding

        const roleIds = useUserStore().userInfo.roleIds.split(",")

        // console.log(" value --", value)
        // console.log(" roleIds --", roleIds)

        if (value && value instanceof Array && value.length > 0) {
            const has = roleIds.some(e => {
                return value.includes(e)
            })

            // console.log("ROLE has --", has)

            if (!has) el.parentNode && el.parentNode.removeChild(el)
        } else {
            throw new Error("ROLE 权限不存在")
        }
    }
}
